package com.labweb.conversor;

import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
import javax.faces.convert.Converter;
import javax.faces.convert.ConverterException;

import com.labweb.entidades.Software;
import com.labweb.servicos.SoftwareService;


public class SoftwareConverter implements Converter{

	
	@Override
	public Object getAsObject(FacesContext context, 
	UIComponent component, String value) 
	throws ConverterException {
		if (value == null) {
			return null;
		}
		return new SoftwareService()
		.pesquisarPorId(Integer.parseInt(value));
	}
	
	@Override
	public String getAsString(FacesContext context, 
	UIComponent component, Object object) 
	throws ConverterException {
			if (object == null) {
				return null;
			}
			Software software = (Software) object;
			return software.getId().toString();
	}

}
